/*
 * @Author: ChunLai
 * @Date: 2022-08-26 15:34:35
 * @LastEditTime: 2024-01-04 14:52:14
 * @Description: 全局公共方法
 * @FilePath: \01.latest-short-insure\src\methods\globals.js
 */
import store from "@/store/index";

export const userAge = (date, addVal = 0) => {
  if (!date) {
    return 0;
  }
  let aDay = 0;
  let birthdays = new Date(date.replace(/-/g, "/"));
  // 生日 T+N 数据配置
  const pageState = store.state.page;
  if (pageState.beginInsDay !== 0) {
    aDay = pageState.beginInsDay;
  }
  if (addVal !== 0) {
    aDay = addVal;
  }
  if (aDay !== 0) {
    const birth2 = birthdays.getTime() + 24 * 60 * 60 * 1000 * aDay;
    birthdays = new Date(birth2);
  }
  // console.log(birthdays)
  let d = new Date();
  let age =
    d.getFullYear() -
    birthdays.getFullYear() -
    (d.getMonth() < birthdays.getMonth() ||
    (d.getMonth() == birthdays.getMonth() && d.getDate() < birthdays.getDate())
      ? 1
      : 0);
  return age;
};

export const removeToViewEle = (eleId) => {
  document.getElementById(eleId).scrollIntoView({
    behavior: "smooth",
    block: "center",
  });
};

// this.$GlobalFuns.

// import {userAge} from "@/methods/globals.js";
